package kr.saeildamil.androidstudty.ch12;

import java.util.ArrayList;

import kr.saeildamil.androidstudty.R;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewTest extends Activity {
	String[] arr;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listviewtest);
		arr=getResources().getStringArray(R.array.country); //클릭시 컨트리 정보 표시 준비
		
		//데이터 원본 준비
		/*ArrayList<String>arList=new ArrayList<String>();
		arList.add("이순신");
		arList.add("강감찬");
		arList.add("을지문덕");
		arList.add("김유신");
		arList.add("연개소문");
		arList.add("세종대왕");*/
		//String[] arList={"이순신","강감찬","을지문덕","김유신","연개소문","세종대왕"};
		
		//리소스의 배열을 원본으로 준비
		ArrayAdapter<CharSequence>adapter=ArrayAdapter.createFromResource
				(this, R.array.country, 
						//android.R.layout.simple_list_item_single_choice
						android.R.layout.simple_list_item_1
						//android.R.layout.simple_list_item_multiple_choice
						);
		
		//어댑터 준비
		/*ArrayAdapter<String>adapter=
				new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arList);*/
		
		//어댑터를 리스트뷰에 연결
		ListView list=(ListView) findViewById(R.id.ch12_listviewtext_list);
		list.setAdapter(adapter);
		
		list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				String str="position = "+position+" id = "+id+" 항목의 값은 "+arr[position];
				Toast.makeText(ListViewTest.this, str, Toast.LENGTH_SHORT).show();
				
			}
		});
		/*list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		list.setDivider(new ColorDrawable(Color.YELLOW));
		list.setDividerHeight(5);*/
	}
}
